package com.olive.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;

import com.alibaba.fastjson.JSON;
import com.olive.dto.NoticeDTO;
import com.olive.service.MessageSource;

/**
 * @Description: 消息推送
 */
@EnableBinding(MessageSource.class)
public class MessageSender {

	/**
	 * 消息的发送管道
	 */
	@Autowired
	private MessageSource messageSource;

	public void publish(NoticeDTO dto) {
		messageSource.output()
			.send(MessageBuilder.withPayload(dto)
			.build());
		System.out.println("消息发送：<" + JSON.toJSONString(dto) + "> 完成，时间：" + new Date());
	}
}
